<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\ResourceCollection;

class PlayerBetFlowCollection extends ResourceCollection
{
    public $resource;

    public function __construct($resource)
    {
        $this->resource = $resource;
        parent::__construct($resource);
    }

    public function toArray($request)
    {
        if ($this->resource->count() >= 1) {
            foreach ($this->collection as $key => $item) {
                $data[$key]['id'] = $item->id;
                $data[$key]['username'] = $item->username;
                $data[$key]['site_username'] = $item->site_username;
                $data[$key]['game_code'] = $item->game_code;
                $data[$key]['game_unique_key'] = $item->game() ? ($item->game()->unique_key ?? null) : null;
                $data[$key]['main_game_plat_code'] = $item->main_game_plat_code;
                $data[$key]['game_flow_code'] = $item->game_flow_code;
                $data[$key]['bet_amount'] = $item->bet_amount;
                $data[$key]['available_bet_amount'] = $item->available_bet_amount;
                $data[$key]['company_payout_amount'] = $item->company_payout_amount;
                $data[$key]['company_win_amount'] = $item->company_win_amount;
                $data[$key]['plat_type'] = $item->plat_type;
                $data[$key]['lobby_type'] = $item->lobby_type;
                $data[$key]['bet_flow_available'] = $item->bet_flow_available;
                $data[$key]['status'] = $item->status;
                $data[$key]['api_data'] = $item->api_data;
                $data[$key]['bet_time'] = $item->bet_time;
                $data[$key]['created_at'] = $item->created_at->toDateTimeString();
            }
            $this->resource->setCollection(collect($data));
            return [
                $this->resource
            ];
        } else {
            return [];
        }

    }
}
